package com.changgou.search.listener;

import com.changgou.search.config.RabbitMQConfig;
import com.changgou.search.service.EsManagerService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 通过数据监控微服务监控数据库表,如果有变化,发送消息到rabbitMQ消息队列
 *
 * 监听该队列,获得发送的消息,spuId,调用更新索引库的方法,将数据更新到索引库中
 */
@Component
public class GoodsUpListener {

    @Autowired
    private EsManagerService esManagerService;

    /**
     * @param message spuId
     */
    @RabbitListener(queues = RabbitMQConfig.SEARCH_ADD_QUEUE)
    public void receiveMessage(String message){
        System.out.println("接收到的消息 : "+message);
        esManagerService.importDataToEsBySpuId(message);
    }

}
